<?php 
namespace app\index\model;
use think\Model;
use think\Db;
class User extends Model
{
	protected $table = 'user';//表名
    protected $table_val; //数据

	//数据表查询
	public function show($username='null',$userpwd='null',$threeId='null'){
		
		$db = Db::name($this->table);
		// echo $username;die;
		$where = "1=1 ";
		if($userpwd=='null' && $username !='null')
		{
			$where .= "and account='$username'";
		}
		elseif ($username=='null' && $userpwd=='null') {

			$where .= "and tid = '$threeId'";
		    // $data = $db->where($where)->select();
      //       var_dump($data);die;
		}
		else
		{
			$where .= "and account='$username' and password='$userpwd'";
		}

		$data = $db->where($where)->find();
		//返回数据
		return $data;
	}

	// //用户表更新
     public function gai($param){

         $this->guolv($param);
         $result = Db::table($this->table)->select();
         if(!$result){
             return 'nullArr';die;
         }else{

                 $res = Db::table($this->table)->where('account',$this->table_val['account'])->find();
                 if(!$res){
                     return 'null';
                 }else{
//                    var_dump($this->table_val);die;
                     $bool = Db::table($this->table)->where('account',$this->table_val['account'])->update(['tid'=>$this->table_val['tid']]);
                     if($bool){
                         return $res['userId'];
                     }
                 }
         }
     }
     


	//用户表添加
	public function add($param){
		  $this->guolv($param);
          return  Db::table($this->table)->insert($this->table_val);
	}

	// 过滤字段
	public function guolv($data){
		$db = Db::name($this->table);
          //用户表的所有字段
		 $field = $db->getTableFields();
		 //过滤
		 foreach ($data as $k => $v) {
		 	  if(in_array($k,$field)){

	       	 	  $this->table_val[$k]=$v;

		 	  }
		 }
	}
}

 ?>
